package com.jala.demo.service.impl;

import com.jala.cm.PageResult;
import com.jala.demo.mapper.DemoMapper;
import com.jala.demo.model.Demo;
import com.jala.demo.req.PageDemoReq;
import com.jala.demo.service.DemoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2018/3/15.
 */
@Service
public class DemoServiceImpl implements DemoService{
    private final Logger logger= LoggerFactory.getLogger(DemoServiceImpl.class);

    @Autowired
    private DemoMapper demoMapper;

    @Override
    public PageResult<Demo> pageDemoList(PageDemoReq req) {
        logger.info("获取分页信息", req);
        PageResult<Demo> result = new PageResult<Demo>();
        int offset = req.getLimitOffset();
        int pageSize = req.getPageSize();
        List<Demo> users = demoMapper.listDemo(offset, pageSize, req.getName(), req.getId());
        int counts = demoMapper.countDemo(req.getName(), req.getId());
        result.setResults(users);
        result.setTotalResults(counts);
        return  result;
    }

    @Override
    public Demo queryByPrimaryKey(Integer id) {
        return demoMapper.queryByPrimaryKey(id);
    }

    @Override
    public List<Demo> listDemo(Integer id) {
        return null;
    }

    @Override
    public int addDemo(Demo demo) {
        return demoMapper.insert(demo);
    }

    @Override
    public int editDemo(Demo demo) {
        return demoMapper.update(demo);
    }

    @Override
    public int deleteDemo(Integer id) {
        return demoMapper.deleteByPrimaryKey(id);
    }
}
